package bamin.com.bamindaijia.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.aiton.administrator.shane_library.shane.utils.Arith;

import java.util.List;

import bamin.com.bamindaijia.R;
import bamin.com.bamindaijia.model.InvoiceHistory;

public class InvoiceHistoryAdapter extends BaseAdapter {
    private List<InvoiceHistory.DatasBean> mDatas;
    private LayoutInflater inflater;

    public InvoiceHistoryAdapter(Context context, List<InvoiceHistory.DatasBean> datas) {
        inflater = LayoutInflater.from(context);

        mDatas = datas;
    }

    class ViewHolder {
        TextView mTv_price;
        TextView mTv_start;
        TextView mTv_end;
        TextView mTv_time;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_invoice_history, null);
            holder.mTv_price = (TextView) convertView.findViewById(R.id.tv_price);
            holder.mTv_start = (TextView) convertView.findViewById(R.id.tv_start);
            holder.mTv_end = (TextView) convertView.findViewById(R.id.tv_end);
            holder.mTv_time = (TextView) convertView.findViewById(R.id.tv_time);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        InvoiceHistory.DatasBean resultsBean = mDatas.get(position);
        Double finalPrice = resultsBean.getFinalPrice();
        if (finalPrice == null) {
            finalPrice = 0.00;
        }
        holder.mTv_price.setText("" + Arith.get2Double(finalPrice));
        if (resultsBean.getStatusModel().equals("未开发票")) {
            holder.mTv_start.setText("物流状态:"+resultsBean.getStatusModel());
        } else {
            holder.mTv_start.setText("物流号:"+resultsBean.getCourierNumber());
        }
        holder.mTv_end.setText("收件人:"+resultsBean.getConsigneeName());
        holder.mTv_time.setText("开票时间:" + resultsBean.getApplicationTime());
        return convertView;
    }
}